home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / kb_flag.bas < prev    next >
BASIC Source File  |  1993-10-16  |  3KB  |  64 lines

  1. 0 ' program = ---- KB_FLAG -----
  2. 1 'Author: Herb Shear, 1590 Vineyard Dr., Los Altos, CA 94022
  3. 2 'This program demonstrates the KB_FLAG at location 0000:0417
  4. 3 'By setting bits in the KB_FLAG byte you can effective press several
  5. 4 'of the keyboard keys from your program.  When the program expects a
  6. 5 'numeric response have the program `press' NumLock so you can use the
  7. 6 'keypad without further ado.
  8. 7 'A typical statement to do that would be:
  9. 8 'DEF SEG=0:POKE &H417, PEEK(&H417) OR &H20
  10. 100 ' Now, as they say in Algol, leave us BEGIN
  11. 110 CLS: KEY OFF   'let's get a clean slate.
  12. 120 GOSUB 590 ' disable CtrlBrk since we will be pressing those keys.
  13. 130 DEF SEG = &H40 'there are more ways than cats.
  14. 140 DEFINT A-Z     'cause it's even slower without this.
  15. 150 '-------Read DATA words into string array------------------
  16. 160 FOR I = 7 TO 0 STEP -1
  17. 170 READ A$(I)
  18. 180 NEXT
  19. 190 '---Function to extract selected bit from an integer or a byte.--
  20. 200 '  The function must be introduced to the interpreter before it
  21. 210 '  can be called.  So, Mr. FUNCTION, meet Mr. BASIC INTERPRETER.
  22. 220 DEF FNBITVALUE(BYTE,BIT) = BYTE \ 2^BIT MOD 2
  23. 230 '------Set up the fixed portion of the screen display--------
  24. 240 LOCATE 6,10,0:PRINT "The KB_FLAG controls the following functions:"
  25. 250 LOCATE 12,10: PRINT "The KB_FLAG bit pattern "+CHR$(26);
  26. 260 LOCATE 15,8:PRINT "DEF SEG=0: POKE 417, PEEK(417) AND &H     OR &H";
  27. 270 LOCATE 17,4:PRINT "To determine AND value: Turn ON the items you really want to be OFF";
  28. 280 LOCATE 19,5:PRINT "To determine OR value: Turn ON the items you want to be ON.";
  29. 290 LOCATE 25,1: PRINT "Press ESC to exit";  'Always nice to know.
  30. 300 PRINT "  (but be brave and press some other keys first)";
  31. 310 POKE &H17,0       'just to start from the same value each RUN.
  32. 320 ' note that different segement (40 vs 0) requires a different
  33. 330 ' offset (17 vs 417).  Segs left shift 4 bits (one hex digit)
  34. 340 ' before offset is added.  Thus 0000:0417 = 0040:0017 = 0041:0007
  35. 350 ' and that still leaves 63 decimal cats unskinned.
  36. 360 '-------Start of display loop------------
  37. 370 FLAG = PEEK(&H17)   'fetch the current KB_FLAG byte.
  38. 380 LOCATE 12,38
  39. 390 '-------Extract and print each bit-----------
  40. 400 FOR I = 7 TO 0 STEP -1
  41. 410  PRINT USING "# "; FNBITVALUE(FLAG,I);
  42. 420 NEXT
  43. 430 LOCATE 15,55: PRINT USING "\\";HEX$(FLAG);
  44. 440 LOCATE 15,45: PRINT USING "\\"; HEX$((NOT FLAG)AND &HFF);
  45. 450 '------Highlite the word for the set bits--------------
  46. 460 LOCATE 8,2
  47. 470 FOR I = 7 TO 0 STEP -1
  48. 480  IF FNBITVALUE(FLAG,I) THEN BRITE = &HF ELSE BRITE = 7
  49. 490  COLOR BRITE: PRINT A$(I);", ";
  50. 500 NEXT
  51. 510 COLOR 7  'comment this out and find the sneaky bug.
  52. 520 IF INKEY$<>CHR$(27) THEN 370  'Esc to exit
  53. 530 '-------End of display loop--------------
  54. 540 CLS: POKE &H17,0  'Don't leave a mess in your nest.
  55. 550 GOSUB 630 ' enable CtrlBrk
  56. 560 END 'every prog should have one, that's spelled O-N-E.
  57. 570 '------------------------------------------
  58. 580 DATA  Ins, CapsLock, NumLock, ScrollLock ,Alt, Ctrl, LeftShift, RightShift
  59. 590 'save CtrlBrk pointer and point to F000:FF53 dummy return in ROM
  60. 600 DEF SEG = 0: FOR I = 0 TO 3: POINTER%(I) = PEEK(108 + I) :  NEXT
  61. 610 POKE 111,&HF0:POKE 110,0:POKE 109,&HFF:POKE 108,&H53:RETURN
  62. 620 'restore former CtrlBrk pointer
  63. 630 DEF SEG = 0: FOR I = 0  TO 3: POKE 108+I, POINTER%(I): NEXT: RETURN
  64.